package org.micro.rbac;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.micro.rbac.dao.mapper.SysUserMapper;
import org.micro.rbac.service.InitDataService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 系统初始化!!!
 *
 * @author hongsir
 * @since 2024/6/12
 **/
@Slf4j
@Component
@RequiredArgsConstructor
public class Init implements CommandLineRunner {
    private final SysUserMapper userMapper;
    private final InitDataService initDataService;

    @Override
    public void run(String... args) throws Exception {
        Long count = userMapper.selectCount(null);
        if (count > 0) {
            log.warn("无需初始化数据.");
            return;
        }
        initDataService.initData();
        log.info("初始化数据成功.");
    }
}
